﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class newStock : Basic
{
    public string strSGSS = "";  //新股上市
    public string strSGZF = "";  //新股增发
    public string strJRSS = "";  //今日上市股票
    public string strXGSG = "";  //新股申购
    public string strXGQL = "";  //新股全览
    public string strNews = "";  //新股新闻,新股学堂
    public List<NewStock> list = new List<NewStock>();
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = jsonUrl + "stock/NewStockList.ashx?skip=0&top=100";
        string str = Pub.LoadData(url);
        list = JsonConvert.DeserializeObject<List<NewStock>>(str);
        if (list != null)
            list = list.OrderByDescending(o => o.ssrq).ToList();

        strSGSS = sb新股上市().ToString();

        strXGSG = sb新股申购().ToString();

        strJRSS = sb今日上市股票().ToString();

        strXGQL = sb新股全览().ToString();

        strSGZF = sb新股增发().ToString();

        //0902 0907
        strNews = sbNews().ToString();
    }


    protected StringBuilder sbNews()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/NewsListMany.ashx?typeid=0902,0907&top=7";
            string str = Pub.LoadData(url);
            List<NewsList> obj = JsonConvert.DeserializeObject<List<NewsList>>(str);
            foreach (var m in obj)
            {
                #region
                switch (m.typeid)
                {
                    case "0907":
                        {
                            #region
                            sb.AppendLine("<div id=\"xnTab1_1\">");
                            sb.AppendLine("<ul>");
                            foreach (var n in m.list)
                            {

                                sb.AppendLine("<li> ·<a href=\"" + GetNewsUrl("02", m.typeid, n.Id) + "\" class=\"b\">" + n.Title + "</a></li>");

                            }
                            sb.AppendLine("</ul>");
                            sb.AppendLine("</div>");
                            #endregion
                            continue;
                        }
                    case "0902":
                        {
                            #region
                            sb.AppendLine("<div id=\"xnTab1_2\" style=\"display:none;\">");
                            sb.AppendLine("<ul>");
                            foreach (var n in m.list)
                            {

                                sb.AppendLine("<li> ·<a href=\"" + GetNewsUrl("02", m.typeid, n.Id) + "\" class=\"b\">" + n.Title + "</a></li>");

                            }
                            sb.AppendLine("</ul>");
                            sb.AppendLine("</div>");
                            #endregion
                            continue;
                        }
                }
                #endregion
            }
        }
        catch
        { }
        return sb;
    }

    protected StringBuilder sb新股上市()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<NewStock> listSS = list.Where(o => o.ssrq.Value.Date <= DateTime.Now.Date).OrderByDescending(o => o.ssrq).Take(10).ToList();
            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"htable\" id=\"ssTab\">");
            sb.AppendLine("  <thead>");
            sb.AppendLine("  <tr class=\"tbg\">");
            sb.AppendLine("    <td height=\"36\">股票代码</td>");
            sb.AppendLine("    <td>股票名称</td>");
            sb.AppendLine("    <td>上市时间</td>");
            sb.AppendLine("    <td>发行价</td>");
            sb.AppendLine("    <td>开盘价</td>");
            sb.AppendLine("    <td>现价</td>");
            sb.AppendLine("    <td>涨跌幅</td>");
            sb.AppendLine("    <td>券商预测价</td>");
            sb.AppendLine("    <td colspan=\"2\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
            sb.AppendLine("  <thead>");
            sb.AppendLine("      <tr>");
            sb.AppendLine("        <td colspan=\"2\">盈利预测                        （每股收益）</td>");
            sb.AppendLine("      </tr>");
            sb.AppendLine("      <tr>");
            sb.AppendLine("        <td>11E</td>");
            sb.AppendLine("        <td>12E</td>");
            sb.AppendLine("        </tr>");
            sb.AppendLine("  </thead>");
            sb.AppendLine("    </table></td>");
            sb.AppendLine("  </tr>");
            sb.AppendLine("  </thead>");
            sb.AppendLine("  <tbody>");
            foreach (var m in listSS)
            {
                sb.AppendFormat("  <tr>");
                sb.AppendFormat("    <td height=\"24\"><a href=\"{1}gg{0}.shtml\" class=\"b\">{0}</a></td>", OTO.ToStr(m.gpdm, "-"), quoteUrl);
                sb.AppendFormat("    <td><a href=\"{2}gg{1}.shtml\" class=\"b\">{0}</a></td>", OTO.ToStr(m.gpjc, "-"), m.gpdm, quoteUrl);
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDateLine(m.ssrq, 1));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecLine(m.fxjg, 2, "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecLine(m.kpj, 2, "-"));
                sb.AppendFormat("<td align=\"center\" ><span zxj=\"zxj\" code=\"" + m.gpdm + "\" class=\"red\">-</span></td>");
                sb.AppendFormat("<td align=\"center\"><span zdf=\"zdf\" zdfv=\"" + m.fxjg + "\">-</span></td>");
                sb.AppendFormat("    <td>{0}</td>", OTO.ToStr(m.qsycj));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecLine(m.ylyc10E, 2, "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecLine(m.mgsy11E, 2, "-"));
                sb.AppendFormat("  </tr>");
            }
            sb.AppendLine("  </tbody>");
            sb.AppendLine("</table>");

        }
        catch { }
        return sb;
    }

    protected StringBuilder sb新股申购()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<NewStock> listSS = list.OrderByDescending(x => x.fxrq).Take(10).ToList();
            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"htable\" id=\"sgTab\">");
            sb.AppendLine("<thead>");
            sb.AppendLine("<tr class=\"tbg\">");
            sb.AppendLine("  <td height=\"36\">申购代码</td>");
            sb.AppendLine("  <td>股票简称</td>");
            sb.AppendLine("  <td>申购日期</td>");
            sb.AppendLine("  <td>发行价格</td>");
            sb.AppendLine("  <td>发行总数<br />(万股)</td>");
            sb.AppendLine("  <td>网上发行<br />(万股)</td>");
            sb.AppendLine("  <td>申购上限<br />(万股)</td>");
            sb.AppendLine("  <td>发行市盈率<br />(%)</td>");
            sb.AppendLine("  <td>中签号公布日</td>");
            sb.AppendLine("  <td>中签率</td>");
            sb.AppendLine("  <td>预测收益率<br />(%)</td>");
            sb.AppendLine("</tr>");
            sb.AppendLine("</thead>");
            sb.AppendLine("<tbody>");
            foreach (var m in listSS)
            {
                sb.AppendLine("  <tr>");
                sb.AppendFormat("    <td height=\"24\">{0}", OTO.ToStr(m.gpdm, "-"));
                sb.AppendFormat("    <td>{0}", OTO.ToStr(m.gpjc, "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDateLine(m.fxrq, 1));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecLine(m.fxjg, 2, "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecimal(m.fxgs, 10000, 2, "", "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecimal(m.psgs, 10000, 2, "", "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecimal(m.sgsl, 10000, 2, "", "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecimal(m.fxsyl, 1, 2, "", "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDateLine(m.zqhggr,1));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecimal(m.fxzql, 1, 2, "", "-"));
                sb.AppendFormat("    <td>{0}</td>", OTO.ToDecimal(m.ycsyl, 1, 2, "", "-"));
                sb.AppendLine("  </tr>");
            }
            sb.AppendLine("</tbody>");
            sb.AppendLine("</table>");
        }
        catch { }
        return sb;
    }

    protected StringBuilder sb新股增发()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "stock/StockList_ZF.ashx?skip=0&top=6";
            string str = Pub.LoadData(url);
            List<NewStock_ZF> listzf = JsonConvert.DeserializeObject<List<NewStock_ZF>>(str);

            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("  <tr class=\"tableLargeHead\">");
            sb.AppendLine("<td>增发代码</td>");
            sb.AppendLine("<td >股票简称</td>");
            sb.AppendLine("<td >股票代码</td>");
            sb.AppendLine("<td >发行总数</td>");
            sb.AppendLine("<td class=\"lineHeight\">网上发行<br />");
            sb.AppendLine("  (万股)</td>");
            sb.AppendLine("<td class=\"lineHeight\">网下配售<br />");
            sb.AppendLine("  (万股)</td>");
            sb.AppendLine("<td class=\"lineHeight\">发行价<br />");
            sb.AppendLine("  (元)</td>");
            sb.AppendLine("<td >增发上市日</td>");
            sb.AppendLine("</tr>");
            foreach (var m in listzf)
            {
                sb.AppendLine("<tr>");
                sb.AppendFormat("<td>{0}</td>", OTO.ToStr(m.zfdm, "-"));
                sb.AppendFormat("<td><a href=\"{2}gg{1}.shtml\" class=\"b\">{0}</td>", OTO.ToStr(m.gpjc, "-"), OTO.ToStr(m.gpdm, "-"), quoteUrl);
                sb.AppendFormat("<td><a href=\"{1}gg{0}.shtml\" class=\"b\">{0}</td>", OTO.ToStr(m.gpdm, "-"), quoteUrl);
                sb.AppendFormat("<td>" + (m.fxgs / 10000 + m.psgs / 10000) + "</td>");
                sb.AppendFormat("<td>" + m.fxgs / 10000 + "</td>");
                sb.AppendFormat("<td>" + m.psgs / 10000 + "</td>");
                sb.AppendFormat("<td class=\"red\">" + m.fxjg + "</td>");
                sb.AppendFormat("<td>" + OTO.ToDateLine(m.ssrq, 1) + "</td>");
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("</table>");

        }
        catch
        {
            sb = new StringBuilder();
        }
        return sb;
    }

    protected StringBuilder sb今日上市股票()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            XgjyEnty obj = new XgjyEnty();
            obj = JsonConvert.DeserializeObject<XgjyEnty>(Pub.LoadData(jsonUrl + "stock/NewStockCZJY.ashx"));

            //今日上市股票
            List<NewStock> listd = list.Where(o => o.ssrq <= DateTime.Now.Date).ToList();
            DateTime? cdate = listd[0].ssrq;
            listd = list.Where(o => o.ssrq != null && o.ssrq.Value.Date == cdate.Value.Date).ToList();

            string tit = "今日";
            if (cdate.Value.Date != DateTime.Now.Date)
                tit = cdate.Value.Day + "号";

            sb.AppendLine("<div class=\"suggestion left\">");
            sb.AppendLine("<div class=\"ltitlebg left\">" + tit + "上市股票(" + listd.Count + ")</div> ");
            sb.AppendLine("<div class=\"suggestion_1 right\">");
            sb.AppendLine("<ul>");
            foreach (var m in listd)
            {
                sb.AppendLine("<li><a href=\"" + quoteUrl + "gg" + m.gpdm + ".shtml\" class=\"b\">" + m.gpjc + "</a>(" + m.gpdm + ")</li>");
            }
            sb.AppendLine("</ul>");
            sb.AppendLine("</div>");
            sb.AppendLine("<div class=\"clear\"></div>");
            sb.AppendFormat("<div class=\"suggestion_con leftbg\"><span class=\"orange font-weight\">操作建议：</span>{0}</div>", obj.czjy);
            sb.AppendLine("</div>");

            //今日申购股票
            list = list.OrderByDescending(o => o.fxrq).ToList();
            listd = list.Where(o => o.fxrq <= DateTime.Now.Date).ToList();
            cdate = listd[0].fxrq;
            listd = list.Where(o => o.fxrq != null && o.fxrq.Value.Date == cdate.Value.Date).ToList();

            tit = "今日";
            if (cdate.Value.Date != DateTime.Now.Date)
                tit = cdate.Value.Day + "号";

            sb.AppendLine("<div class=\"suggestion left\">");
            sb.AppendLine("<div class=\"suggestion_title rtitlebg left\">" + tit + "申购股票(" + listd.Count + ")</div> ");
            sb.AppendLine("<div class=\"suggestion_1 right\">");
            sb.AppendLine("<ul>");
            foreach (var m in listd)
            {
                sb.AppendLine("<li><a href=\"" + quoteUrl + "gg" + m.gpdm + ".shtml\" class=\"b\">" + m.gpjc + "</a>(" + m.gpdm + ")</li>");
            }
            sb.AppendLine("</ul>");
            sb.AppendLine("</div>");
            sb.AppendLine("<div class=\"clear\"></div>");
            sb.AppendFormat("<div class=\"suggestion_con rightbg\"><span class=\"orange font-weight\">申购建议：</span>{0} </div>", obj.sgjy);
            sb.AppendLine("</div>");

        }
        catch { }
        return sb;
    }

    protected StringBuilder sb新股全览()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            List<NewStock> list2 = list.Take(30).ToList();
            sb.AppendLine("<div class=\"tableLarge\">");
            sb.AppendLine("<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">");
            sb.AppendLine("  <tr class=\"tableLargeHead\">");
            sb.AppendLine("    <td>代码</td>");
            sb.AppendLine("    <td >股票简称</td>");
            sb.AppendLine("    <td >申购代码</td>");
            sb.AppendLine("    <td class=\"lineHeight\">发行总数<br />(万股)</td>");
            sb.AppendLine("    <td class=\"lineHeight\">网上发行<br />");
            sb.AppendLine("      (万股)</td>");
            sb.AppendLine("    <td class=\"lineHeight\">申购上限<br />");
            sb.AppendLine("      (股)</td>");
            sb.AppendLine("    <td >申购日期</td>");
            sb.AppendLine("    <td class=\"lineHeight\">发行价<br />");
            sb.AppendLine("      (元)</td>");
            sb.AppendLine("    <td class=\"lineHeight\">发行市<br />");
            sb.AppendLine("      盈率</td>");
            sb.AppendLine("    <td class=\"lineHeight\">中签率<br />");
            sb.AppendLine("      (%)</td>");
            sb.AppendLine("    <td class=\"lineHeight\">每中一签约<br />");
            sb.AppendLine("      (元)</td>");
            sb.AppendLine("    <td >上市日</td>");
            sb.AppendLine("    <td >当前价(元)</td>");
            sb.AppendLine("    <td class=\"lineHeight\">上市后<br />");
            sb.AppendLine("      涨跌幅");
            sb.AppendLine("      (%)</td>");
            //sb.AppendLine("    <td >详细</td>");
            sb.AppendLine("  </tr>");
            for (int i = 0; i < list2.Count; i++)
            {
                sb.AppendLine("<tr onmouseover=\"this.className='tr_over'\" onmouseout=\"this.className='tr_out'\">");
                sb.AppendFormat("  <td><a href=\"{1}gg{0}.shtml\" class=\"b\">{0}</td>", OTO.ToStr(list2[i].gpdm), quoteUrl);
                sb.AppendFormat("  <td><a href=\"{2}gg{1}.shtml\" class=\"b\">{0}</a></td>", OTO.ToStr(list2[i].gpjc), OTO.ToStr(list2[i].gpdm), quoteUrl);
                sb.AppendLine("  <td>" + OTO.ToStr(list2[i].sgdm, "&nbsp;") + "</td>");
                sb.AppendLine("  <td>" + OTO.CoUt(list2[i].zfxgs, 10000, "", 0) + "</td>");
                sb.AppendLine("  <td>" + OTO.CoUt(list2[i].fxgs, 10000, "", 0) + "</td>");
                sb.AppendLine("  <td>" + OTO.ToLongLine(list2[i].sgsl, "-") + "</td>");
                sb.AppendLine("  <td>" + OTO.ToDateLine(list2[i].fxrq, 1) + "</td>");
                sb.AppendLine("  <td class=\"red\">" + OTO.ToDecLine(list2[i].fxjg, 2, "-") + "</td>");
                sb.AppendLine("  <td>" + OTO.ToDecLine(list2[i].fxsyl, 2, "-") + "</td>");
                sb.AppendLine("  <td>" + OTO.ToDecLine(list2[i].fxzql, 2, "-") + "</td>");
                sb.AppendLine("  <td>" + OTO.ToDecLine(list2[i].Fxqy, 2, "-") + "</td>");
                sb.AppendLine("  <td>" + OTO.ToDateLine(list2[i].ssrq, 1) + "</td>");
                sb.AppendLine("<td align=\"center\" ><span zxj=\"zxj\" code=\"" + list2[i].gpdm + "\" class=\"red\">-</span></td>");
                sb.AppendLine("<td align=\"center\"><span zdf=\"zdf\" zdfv=\"" + list2[i].fxjg + "\">-</span></td>");
                //sb.AppendLine("  <td class=\"blue\">详细</td>");
                sb.AppendLine("</tr>");
            }
            sb.AppendLine("    </table>");
            sb.AppendLine("</div>");
        }
        catch { }
        return sb;
    }

}